<!--#include file="pjson.asp"-->
<!DOCTYPE html>
<html>
<head>
  <title>工单日志管理</title>
<%
sessionExpire
easp.include "h.asp"
dim tn
tn="log1"
cszdgb
function cszdgb()'自动关闭超时工单（10天前的工单）
	dim arr,w,i
	vas "ed",Format_Time(now()-10,2)
	w="(submitTime<=#"&val("ed") & " 23:59:59# and status=899)"
	vas "status","1032"
	execsw xg("log1","status",w)
	vas "status",""
	
	'arr=sql2arr("select id from log1 where " & w & " and status=899" )
	'echo ubound(arr,1)
	'echo "<br>"
	'echo ubound(arr,2)
end function
%>
</head>
<body>
<div class="layui-row layui-col-space20">
    <div class="layui-col-md9">
		<div class="layui-card"><br>
		  <div class="layui-form layui-card-header layuiadmin-card-header-auto">
			<div class="layui-form-item">
				<div class="layui-inline">
				  <label class="layui-form-label">开始日期</label>
				  <div class="layui-input-inline">
					<% input "sd","yyyy-MM-dd"%>
				  </div>
				</div>
				<div class="layui-inline">
				  <label class="layui-form-label">结束日期</label>
				  <div class="layui-input-inline">
					<% input "ed","yyyy-MM-dd"%>
				  </div>
				</div>		
			  <div class="layui-inline">
				<label class="layui-form-label">检索</label>
				<div class="layui-input-inline">
				  <input type="text" id="<%=tn%>_search" name="<%=tn%>_search" class="layui-input">
				</div>
			  </div>
			 <div class="layui-inline">			
				<%
				echo myopt2_no_required("typ","工单类型",sql2arr("select id,name1 from baseinfo where mode='工单类型' "),iif(val("typ") = "",0,val("typ")))
				%>
			 </div>
			 <div class="layui-inline">	
				<%	
				echo myopt2_no_required("status","工单状态",sql2arr("select id,name1 from baseinfo where mode='工单状态'"),iif(val("status") = "",0,val("status")))
				%>    
			 </div>
			 <div class="layui-inline">				 
			 	<%echo myopt2_no_required("repairerId","接单人",sql2arr("select id,truename from [user] where user_typ=978"),iif(val("repairerId") = "",session("user_id"),val("repairerId")))%>
			</div>
			 <div class="layui-inline">
				<button class="layui-btn layuiadmin-btn-useradmin" lay-submit lay-filter="my<%=tn%>_search" id="my<%=tn%>_search">
				  <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
				</button>
				  <button type="button" class="layui-btn" lay-submit lay-filter="<%=tn%>_add2">新增工单</button>			
				  <button type="button" class="layui-btn" lay-submit lay-filter="<%=tn%>_test">超时工单</button>			
			 </div>
			</div>
		  </div>
			<blockquote class="layui-elem-quote layui-quote-nm">
			  双击表格行，可书写心得。
			  <br>——纵横
			</blockquote>		  

		  <div class="layui-card-body">
			<script type="text/html" id="barDemo">
				<a class="layui-btn layui-btn-xs" lay-event="<%=tn%>_edit">维护</a>
				<a class="layui-btn layui-btn-primary layui-btn-xs" lay-event="<%=tn%>_tlp">过程</a>			
				<a class="layui-btn layui-btn-xs" lay-event="<%=tn%>_show">分享</a>	
				<a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="<%=tn%>_del">删除</a>	
			</script>
			<table id="<%=tn%>" lay-filter="<%=tn%>"></table><br>
		  </div>
		</div>
	</div>
	<div class="layui-col-md3">
	  <div class="layui-card">
	  <div class="layui-card-header">工单看板<span id='Interval'></span> </div>
	  <div class="layui-card-body">
		<div class="layui-carousel layadmin-carousel layadmin-backlog">
		  <div carousel-item>
			<ul class="layui-row layui-col-space10">
			  <li class="layui-col-xs6">
				<a href="javascript:;" class="layadmin-backlog-body">
				  <h3>今日待接单</h3>
				  <p><cite id='todayundistribute'></cite></p>
				</a>
			  </li>
			  <li class="layui-col-xs6">
				<a href="javascript:;" class="layadmin-backlog-body">
				  <h3>预约服务器</h3>
				  <p><cite id='myg'></cite></p>
				</a>
			  </li>
			  <li class="layui-col-xs6">
				<a href="javascript:;" class="layadmin-backlog-body">
				  <h3>进行中工单</h3>
				  <p><cite id='process'></cite></p>
				</a>
			  </li>
			  <li class="layui-col-xs6">
				<a id="log1_overtime_l" href="" class="layadmin-backlog-body">
				  <h3>超时工单</h3>
				  <p><cite id='overtime' style="color: #FF5722;"></cite></p>
				</a>
			  </li>

			</ul>
			<ul class="layui-row layui-col-space10">
			  <li class="layui-col-xs6">
				<a href="javascript:;" class="layadmin-backlog-body">
				  <h3>总待接单</h3>
				  <p><cite id='undistribute'></cite></p>
				</a>
			  </li>
			  <li class="layui-col-xs6">
				<a href="javascript:;" class="layadmin-backlog-body">
				  <h3>总共完成工单</h3>
				  <p><cite id='done'></cite></p>
				</a>
			  </li>
			</ul>
		  </div>
		</div>
	  </div>
	</div>
	
	
	  <div class="layui-card">
	  <div class="layui-card-header">工单动态<span id='Interval'></span> </div>
	  <div class="layui-card-body">
			<table id="<%=tn%>_sum" lay-filter="<%=tn%>_sum"></table><br>

	  </div>
	</div>
	</div>
</div>
  <script src="/<%=rootpath%>/src/layuiadmin/layui/layui.js"></script>  
  <script>
  layui.config({
    base: '/<%=rootpath%>/src/layuiadmin/'
  }).extend({
    index: 'lib/index' //主入口模块
  }).use(['index', 'console','useradmin', 'table','laydate'], function(){
    var $ = layui.$
    ,form = layui.form
    ,admin = layui.admin	
    ,table = layui.table;
	var myvar=0;
	alertFunc()
	myFunction();
	$("#<%=tn%>_search").keypress(function (even) {
	   if (even.which == 13) {
				$("#my<%=tn%>_search").trigger("click");
				return false;
		}
	});

	var laydate = layui.laydate;	
	laydate.render({
		elem: '#sd'
		,value: '<%=Format_Time(now()-5,2)%>'	
	  });	
	laydate.render({
		elem: '#ed'
		,value: '<%=Format_Time(now(),2)%>'	
	  });	
    form.render();
	table.render({
        elem: '#<%=tn%>',
        url: 'pjson.asp?action=<%=tn%>_l',
        cols: [[
		//{type:'checkbox'},		
        {field: 'id',title: 'ID',width: 60,sort: true,hide:true},
        <%
		g_tbf "typ:0,typ_name:95,equipmentId:0,equipmentname:0,questionDescription:250,declare:80,declareTele:120,submitTime:160,status:0,name1,truename","typ,工单类型,equipmentId,打印机型号,问题描述,提交人,联系电话,提交时间,status,工单状态,接单人"
		%>
        {fixed: 'right',width: 220,align: 'center',toolbar: '#barDemo'}]],
        id: '<%=tn%>',
        limit: 10,
        page: true,
        height: 475
    });
	
	table.render({
        elem: '#<%=tn%>_sum',
        url: 'pjson.asp?action=<%=tn%>_sum',
        cols: [[
        {field: 'truename',title: '姓名',width: 80,sort: true},
        <%
		g_tbf "cnt1:80,cnt2:80,cnt3:80","处理中,已处理,已关闭"
		%>
       ]],
        id: '<%=tn%>_sum',
        height: 275
    });
	
	function log1_overtime_l(){
      layer.open({
        type: 2,skin: 'layui-layer-molv',title: '超时工单',content: '<%=tn%>_overtime_l.asp?now=' + new Date().getTime() +"&type=<%=tn%>",maxmin: true
        ,area: ['600px', '450px']
		,btn: ['确定', '取消']
        ,success: function(layero, index){
			//layer.full(index);
        }
      });		
	}
	$('#log1_overtime_l').click(function(e){
		log1_overtime_l();
		e.preventDefault();
	});
	
    form.on('submit(<%=tn%>_test)', function(data){
		log1_overtime_l();
		
		/*var field = data.field;
		$.post('pjson.asp?now=' + new Date().getTime(), {
			action: "test",
			field,page:1,limit:10
		},
		function(data) {
			var jsonObj = $.parseJSON(data).data;
			$.each(jsonObj,function(i,item){
				alert(i + item.questionDescription);
			});
		});*/ 
    });	

function myFunction() {
    setInterval(alertFunc, 1000*30*20);
}
function alertFunc() {
	$.post('pjson.asp?now=' + new Date().getTime()+"&need_mysql=1", {
		action: "compute_log1"
	},function(data){
			$('#Interval').text(myvar);
			//alert(data);
			var jsonObj = $.parseJSON(data).data;
			$.each(jsonObj,function(i,item){
				$('#todayundistribute').text(item.todayundistribute);
				$('#process').text(item.process);
				$('#undistribute').text(item.undistribute);
				$('#overtime').text(item.overtime);
				$('#myg').text(item.myg);
				$('#done').text(item.done);
			});
	} );
	myvar++;
	return;
//边缘弹出
layer.open({
  type: 1
  ,offset: 'rt' //具体配置参考：offset参数项
  ,content: '<div style="padding: 20px 80px;">'+myvar+'</div>'
  ,btn: '关闭'
  ,btnAlign: 'c' //按钮居中
  ,isOutAnim: false
  ,shade: 0 //不显示遮罩
  //,title: false
  ,closeBtn: 0
  ,time: 5000
  //,anim: 3
  , skin: 'layui-layer-molv' //默认皮肤
  ,yes: function(){
    layer.closeAll();
  }
});
}	
  table.on('rowDouble(<%=tn%>)', function(obj){
    var data = obj.data;
    //标注选中样式
    obj.tr.addClass('layui-table-click').siblings().removeClass('layui-table-click');
      layer.open({
		type: 2,skin: 'layui-layer-molv' ,title: '心得',content: '/kindeditor/asp/ke.asp?now=' + new Date().getTime() +"&log1_id="+data.id,maxmin: true
		//type: 2,title: '心得',content: 'fwb_frm.asp?now=' + new Date().getTime() +"&log1_id="+data.id,maxmin: true
        ,area: ['650px', '495px']
        //,btn: ['确定', '取消']
		,success: function(layero, index){
			console.log(layero, index);
  		}
      });	
  });	
	form.on('select(typ)', function(data){
		console.log(data.elem); //得到select原始DOM对象
		console.log(data.value); //得到被选中的值
		console.log(data.othis); //得到美化后的DOM对象
	}); 

    form.on('submit(my<%=tn%>_search)', function(data){
 	  var field = data.field;
	         console.log(data.elem) //被执行事件的元素DOM对象，一般为button对象
  console.log(data.form) //被执行提交的form对象，一般在存在form标签时才会返回
  console.log(data.field) //当前容器的全部表单字段，名值对形式：{name: value}
      table.reload('<%=tn%>', {
        where: field
      });
      layer.msg('已刷新');
    });	
    form.on('submit(<%=tn%>_add2)', function(data){
      layer.open({
        type: 2,skin: 'layui-layer-molv',title: '新增工单',content: '<%=tn%>_frm.asp?now=' + new Date().getTime() +"&type=<%=tn%>",maxmin: true
        ,area: ['500px', '450px']
        ,btn: ['确定', '取消']
        ,yes: function(index, layero){
          var iframeWindow = window['layui-layer-iframe'+ index]
          ,submitID = 'LAY-user-front-submit'
          ,submit = layero.find('iframe').contents().find('#'+ submitID);
          iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
            var field = data.field; 
			console.log(field);
				$.post('pjson.asp?now=' + new Date().getTime()+"&need_mysql=1", {
					action: "<%=tn%>_add2",
					field
				},
				function(data) {
					layer.msg($.parseJSON(data).msg);
				});
            table.reload('<%=tn%>'); 
            layer.close(index); 
          });  
          submit.trigger('click');
        }
        ,success: function(layero, index){
        }
      });	
    });	

    table.on('tool(<%=tn%>)',
    function(obj) {
        var data = obj.data;
		if (obj.event === '<%=tn%>_edit') {
			var _this = $(this);
			  layer.open({
				type: 2
				,skin: 'layui-layer-molv'
				,title: '工单维护'
				,content: '<%=tn%>_frm.asp?now=' + new Date().getTime()+"&id="+data.id+"&status="+data.status
				,maxmin: true
				,area: ['500px', '450px']
				,btn: ['确定', '取消']
				,yes: function(index, layero){
				  var iframeWindow = window['layui-layer-iframe'+ index]
				  ,submitID = 'LAY-user-front-submit'
				  ,submit = layero.find('iframe').contents().find('#'+ submitID);
				  iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
					var field = data.field; 
						$.post('pjson.asp?now=' + new Date().getTime()+"&need_mysql=1", {
							action: "<%=tn%>_upd",
							field
						},
						function(data) {
							layer.msg($.parseJSON(data).msg);
						});
					table.reload('<%=tn%>'); //数据刷新
					layer.close(index); //关闭弹层
				  });  
				  submit.trigger('click');
				}
				,success: function(layero, index){
				}
				});				
			table.reload('<%=tn%>');
		}		
		else if (obj.event === '<%=tn%>_tlp') {
			var _this = $(this);
			  layer.open({
				type: 2
				, skin: 'layui-layer-molv'
				,title: '工单过程追踪'
				,content: '<%=tn%>_tlp_frm.asp?now=' + new Date().getTime()+"&id="+data.id+"&status="+data.status
				,maxmin: true
				,area: ['500px', '450px']
				,btn: ['确定', '取消']
				,yes: function(index, layero){
				  var iframeWindow = window['layui-layer-iframe'+ index]
				  ,submitID = 'LAY-user-front-submit'
				  ,submit = layero.find('iframe').contents().find('#'+ submitID);
				  iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
					var field = data.field; 
						$.post('pjson.asp?now=' + new Date().getTime(), {
							action: "<%=tn%>_tlp_add",id:data.id,status:data.status,
							field
						},
						function(data) {
							var jsonObj = $.parseJSON(data);
							layer.msg(jsonObj.msg);
						});
					table.reload('<%=tn%>'); //数据刷新
					layer.close(index); //关闭弹层
				  });  
				  submit.trigger('click');
				}
				,success: function(layero, index){
				}
				});			
		}
		else if (obj.event === '<%=tn%>_show') {
			var _this = $(this);
			  layer.open({
				type: 2
				,title: '文件分享'
				,content: '<%=tn%>_xd_show.asp?now=' + new Date().getTime()+"&id="+data.id+"&status="+data.status+"&log1_id="+data.id
				,maxmin: true
				,area: ['500px', '450px']
				,btn: ['确定', '取消']
				,yes: function(index, layero){
				  var iframeWindow = window['layui-layer-iframe'+ index]
				  ,submitID = 'LAY-user-front-submit'
				  ,submit = layero.find('iframe').contents().find('#'+ submitID);
				  iframeWindow.layui.form.on('submit('+ submitID +')', function(data){
					var field = data.field; 
						$.post('pjson.asp?now=' + new Date().getTime(), {
							action: "<%=tn%>_tlp_add",id:data.id,status:data.status,
							field
						},
						function(data) {
							var jsonObj = $.parseJSON(data);
							layer.msg(jsonObj.msg);
						});
					table.reload('<%=tn%>'); //数据刷新
					layer.close(index); //关闭弹层
				  });  
				  submit.trigger('click');
				}
				,success: function(layero, index){
				}
				});			
		}
		else if (obj.event === '<%=tn%>_del') {
			var _this = $(this);
			layer.confirm('您确定删除此信息？' + data.id, {
				icon: 3,
				title: '提示信息'
			},
			function(index) {
				$.post('pjson.asp?now=' + new Date().getTime(), 
				{
					id: data.id
					,action: "<%=tn%>_del"
				},
				function(data) 
				{
					layer.msg($.parseJSON(data).msg);
				});
				layer.close(index);
				table.reload('<%=tn%>');				
			});
		}	
	});		
  });
  </script>
</body>
</html>